class Stack(object):
    def __init__(self):
        self.items=[]
    def push(self,item):
        self.items.append(item)
    def pop(self):
        return self.items.pop()
    def peek(self):
        return self.items[len(self.items)-1]
    def isEmpty(self):
        return self.items==[]
    def size(self):
        return len(self.items)

def StackXS(items):
    s=Stack()
    index=0
    balances=True
    while index<len(items) and balances:
        item=items[index]
        if item =='S':
            s.push(item)
        else:
           if s.isEmpty():
               balances = False
           elif item=="X":
               s.pop()

        index+=1

    if balances and s.isEmpty():
        return "YES"
    else:
        return "NO"

N,M=map(int,input().split())
lt=[]
for _ in range(N):
    s=input()
    lt.append(s)
for s in lt:
    if len(s)>M and M<=50:
        print("NO")
    else:
        stacks=StackXS(s)
        print(stacks)